package com.newcapec.modules.pass.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newcapec.common.utils.PageUtils;
import com.newcapec.common.utils.Query;
import com.newcapec.modules.pass.dao.TemporaryAccessDao;
import com.newcapec.modules.pass.entity.TemporaryAccessEntity;
import com.newcapec.modules.pass.service.TemporaryAccessService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("temporaryAccessService")
public class TemporaryAccessServiceImpl extends ServiceImpl<TemporaryAccessDao, TemporaryAccessEntity> implements TemporaryAccessService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String customerId = (String) params.get("customerId");
        String studentName = (String) params.get("studentName");
        String stuNo = (String) params.get("stuNo");
        String building = (String) params.get("building");
        String status = (String) params.get("status");
        String createTime = (String) params.get("createTime");
        String approveTime = (String) params.get("approveTime");
        IPage<TemporaryAccessEntity> page = this.page(
                new Query<TemporaryAccessEntity>().getPage(params, "create_time", false),
                new QueryWrapper<TemporaryAccessEntity>()
                        .eq(StringUtils.isNotBlank(customerId), "customer_id", customerId)
                        .like(StringUtils.isNotBlank(studentName), "name", studentName)
                        .like(StringUtils.isNotBlank(stuNo), "stu_no", stuNo)
                        .like(StringUtils.isNotBlank(building), "building", building)
                        .eq(StringUtils.isNotBlank(status), "status", status)
                        .apply(StringUtils.isNotBlank(createTime), "date_format(create_time,'%Y-%m-%d') = {0}", createTime)
                        .apply(StringUtils.isNotBlank(approveTime), "date_format(approve_time,'%Y-%m-%d') = {0}", approveTime)
        );

        return new PageUtils(page);
    }

}